<template>
  <el-menu
    default-active="2"
    class="el-menu-vertical-demo"
    :collapse="isCollapse"
    background-color="rgb(219 234 254)"
    :router="true"
  >
    <el-sub-menu
      v-for="(subNode, index) in menuList.filter((item) => item.pid === 1)"
      :key="'sub-' + index"
      :index="index"
    >
      <template #title>
        <el-icon><Promotion /></el-icon>
        {{ subNode.title }}
      </template>

      <el-menu-item
        v-for="(itemNode, index) in menuList.filter((item) => item.pid === subNode.id)"
        :key="index"
        :index="itemNode.path"
      >
        <el-icon><Menu /></el-icon>
        {{ itemNode.title }}
      </el-menu-item>
    </el-sub-menu>
  </el-menu>
</template>

<script setup>
import { Menu, Promotion } from '@element-plus/icons-vue'
import { useMenuStore } from '@/stores/home/menu.js'
import { storeToRefs } from 'pinia'
import { onMounted } from 'vue'

const menuStore = useMenuStore()
const { isCollapse, menuList } = storeToRefs(menuStore)

onMounted(() => {
  menuStore.getMenu()
})
</script>

<style>
.el-menu {
  border-right: 0;
  height: 100%;
}

.el-menu-vertical-demo:not(.el-menu--collapse) {
  width: 100%;
  min-height: 100%;
}
</style>
